//
// Created by root on 2022/3/19.
//
#include <stdio.h>
#include <string.h>

void testMemory();
int main(){

    int length = 5;
    int aa[length];

    int a[5];
    int b[5] = {0};
    int c[5] = {1};
    int d[5] = {4, 5};
    int e[5] = {[3] = 4};
    int f[] = {[3] = 4};

    for (int i = 0; i < 6; ++i) {
        printf("AA: i is %d, value is %d \n", i, aa[i]);
    }

    // 不会产生数组越界错误
    for (int i = 0; i < 6; ++i) {
        printf("A: i is %d, value is %d \n", i, a[i]);
    }
    for (int i = 0; i < 5; ++i) {
        printf("B: i is %d, value is %d \n", i, b[i]);
    }

    for (int i = 0; i < 5; ++i) {
        printf("C: i is %d, value is %d \n", i, c[i]);
    }

    for (int i = 0; i < 5; ++i) {
        printf("D: i is %d, value is %d \n", i, d[i]);
    }
    for (int i = 0; i < 5; ++i) {
        printf("E: i is %d, value is %d \n", i, e[i]);
    }
    for (int i = 0; i < 5; ++i) {
        printf("F: i is %d, value is %d \n", i, f[i]);
    }
//    for (int i = 0; i < 100000; ++i) {
//        testMemory();
//    }
}

void testMemory(){
    int a[500]={0};

    // 这个变量会一直保存在内存中，每次进入方法都会 + 500
    static int count = 0;
    count+= 500;

    for (int i = 0; i < 500; ++i) {
//        printf("%d,", a[i]);
        a[i] = 100000;
    }
    printf(" count %d \n", count);
}